package com.ruoyi.generator.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.generator.mapper.FromBuildFormConfigMapper;
import com.ruoyi.generator.domain.FromBuildFormConfig;
import com.ruoyi.generator.service.IFromBuildFormConfigService;

/**
 * 单设计__单属性事件配置Service业务层处理
 *
 * @author ZGL
 * @date 2025-03-07
 */
@Service
public class FromBuildFormConfigServiceImpl implements IFromBuildFormConfigService
{
    @Autowired
    private FromBuildFormConfigMapper fromBuildFormConfigMapper;

    /**
     * 查询单设计__单属性事件配置
     *
     * @param id 单设计__单属性事件配置主键
     * @return 单设计__单属性事件配置
     */
    @Override
    public FromBuildFormConfig selectFromBuildFormConfigById(Long id)
    {
        return fromBuildFormConfigMapper.selectFromBuildFormConfigById(id);
    }

    /**
     * 查询单设计__单属性事件配置列表
     *
     * @param fromBuildFormConfig 单设计__单属性事件配置
     * @return 单设计__单属性事件配置
     */
    @Override
    public List<FromBuildFormConfig> selectFromBuildFormConfigList(FromBuildFormConfig fromBuildFormConfig)
    {
        return fromBuildFormConfigMapper.selectFromBuildFormConfigList(fromBuildFormConfig);
    }

    /**
     * 新增单设计__单属性事件配置
     *
     * @param fromBuildFormConfig 单设计__单属性事件配置
     * @return 结果
     */
    @Override
    public int insertFromBuildFormConfig(FromBuildFormConfig fromBuildFormConfig)
    {
        fromBuildFormConfig.setCreateTime(DateUtils.getNowDate());
        return fromBuildFormConfigMapper.insertFromBuildFormConfig(fromBuildFormConfig);
    }

    /**
     * 修改单设计__单属性事件配置
     *
     * @param fromBuildFormConfig 单设计__单属性事件配置
     * @return 结果
     */
    @Override
    public int updateFromBuildFormConfig(FromBuildFormConfig fromBuildFormConfig)
    {
        fromBuildFormConfig.setUpdateTime(DateUtils.getNowDate());
        return fromBuildFormConfigMapper.updateFromBuildFormConfig(fromBuildFormConfig);
    }

    /**
     * 批量删除单设计__单属性事件配置
     *
     * @param ids 需要删除的单设计__单属性事件配置主键
     * @return 结果
     */
    @Override
    public int deleteFromBuildFormConfigByIds(Long[] ids)
    {
        return fromBuildFormConfigMapper.deleteFromBuildFormConfigByIds(ids);
    }

    /**
     * 删除单设计__单属性事件配置信息
     *
     * @param id 单设计__单属性事件配置主键
     * @return 结果
     */
    @Override
    public int deleteFromBuildFormConfigById(Long id)
    {
        return fromBuildFormConfigMapper.deleteFromBuildFormConfigById(id);
    }

    /**
     * 新增单设计__表单属性、事件配置
     */
    @Override
    public int refreshFormConfig(String formBuildKey, FromBuildFormConfig fromBuildFormConfig){

        if(StringUtils.isEmptyIncludeNull(formBuildKey)){
            return 0;
        }

        //删除之前的配置信息
        fromBuildFormConfigMapper.deleteFromBuildFormConfigByBuildKey(formBuildKey);
        //保存当前的配置信息
        if(fromBuildFormConfig!=null){
            fromBuildFormConfig.setBuildKey(formBuildKey);
            fromBuildFormConfig.setUpdateTime(new Date());
            fromBuildFormConfigMapper.insertFromBuildFormConfig(fromBuildFormConfig);
        }
        return 1;
    }

    /**
     * 获取单设计__表单属性、事件配置
     * @param formBuildKey
     * @return
     */
    @Override
    public FromBuildFormConfig getFormConfig(String formBuildKey){
        return fromBuildFormConfigMapper.getFormConfigByBuildKey(formBuildKey);
    }
}
